<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="../../js/lib/jquery-1.11.2.min.js"></script>
    <script src="../../js/lib/html2canvas.js"></script>
</head>
<body>
<div id="capture" style="padding: 10px; background: #f5da55">
    <h4 style="color: #000; ">Hello world!</h4>
</div>
<button id="btn_screen">点击获取图片</button>

<script>
    $("#btn_screen").on("click", function () {
        html2canvas(document.querySelector("#capture")).then(function(canvas) {
            document.body.appendChild(canvas);
            convertCanvasToImage(canvas)
        });
        function convertCanvasToImage(canvas) {
            var image = new Image();
            image.src = canvas.toDataURL("image/png");
            console.log(image.src)
            return image;
        }
    })
</script>
</body>
</html>